/* ----------------------------------------------------------------------------

	pax.widget.inputbox.js Copyright (C) 2005, 2008 Mikkel Bergmann, Pointful

	Licence
	-------
	
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

	See lgpl.txt for licence details

---------------------------------------------------------------------------- */


/*
	Script: pax.widget.inputbox
		This is an auto-complete box
		
	Author:
		Mikkel Bergmann, <http://www.pointful.com>

	Note:
		This is yet to be re-written, to use the PAX widget library.

*/


var pax = pax || {};
pax.widget = pax.widget || {};
pax.widget.inputbox = pax.widget.inputbox || {};


/*
	The displayField and serverSearchScript are mandatory, valueField is optional.
*/


/*	Method: pax.widget.inputbox.init
	Initialises an input box for ajax input
	
	Parameters:		
		displayField - the field we display / edit the value in
		serverSearchScript - The name of the script to call on the server
		valueField - Optionally you can choose a seperate field to store the data in. By default this is the same as the displayField

	Returns:
		nothing

	Example:
		(start code)
			Input box example: start by typing 'la' in the box below:
			<form name='inputBoxForm' onsubmit='return false;'>
				<span>
					<input name="town" id="town">
				</span>
			</form>
			This example uses a static php file, with a random selection of 300 Australian town names from NSW. 
			It will show an input box where you can quickly find town names, via three diffrent methods:
			<ul>
				<li><b>Start match</b> - matches from the start of the value string</li>
				<li><b>Partial match</b> - matches anywhere within the value string</li>
				<li><b>Sounds like</b> - matches on complete values that sound like the string (using a soundex lookup)</li>
			</ul>
			Click on the icon at the end of the text box, to configure a different search method.
			[:.
				pax.widget.inputbox.init( pax.$('town'), '/pax/documentation/pax.widget.inputbox.example.php' );
				exampleCleanup = function() { 
					pax.widget.inputbox.hideMessageBox( 'town_icon' );
				};
			:]
		(end)
*/
pax.widget.inputbox.init = function( displayField, serverSearchScript, valueField  ) {
	valueField = ( typeof valueField != 'undefined' && valueField )? valueField : displayField;	// The valueField is the same as the displayField if it has not been specified.

	// System variables - defaults
	displayField.inputboxConfig = {};	// Config OBJ is attached to the displayField
	var cfg = displayField.inputboxConfig;
	
	cfg.valueField = valueField;
	cfg.serverSearchScript = serverSearchScript;
	cfg.serverSearchScript = serverSearchScript;

	cfg.searchDelay = 500;				// Time in ms to delay the search
	cfg.minSearchLength = 1;			// Minimum chars to input before searching
	cfg.resultWidth = 20;				// Length of each string to display from the result
	cfg.useIndex = false;				// Use the index value rather than the displayed value (like a select dropdown)
	cfg.selectResult = true;			// Display the matching text as "normal", and the rest as selected text
	cfg.allowFreetext = false;			// Allow the user to enter free format text, or only one of the choices from the result
	cfg.searchMode = 'default';			// Which search mode to be in by default
	//	cfg.showConfigIcon = false;			// Do we show the configuration icon?
	cfg.showConfigIcon = true;			// Do we show the configuration icon?
	
	// System variables - don't touch!
	cfg.useIndex = ( cfg.valueField != displayField );		// Always use index value, if we have a seperate displayFieldID
	cfg.originalValue = '';				// The original value of the field
	cfg.lastSearch = '';				// Previous search string
	cfg.token = 0;						// Token to pass to backend.
	cfg.requestTimer = null;			// The timeout variable.
	cfg.result = {};					// The result
	cfg.resultCount = 0;				// Count of results
	cfg.resultOffset = 0;				// Offset of chosen result.
	cfg.resultDiv = 'inputboxResult_' + displayField.id;
	cfg.originalValue = valueField.value;

	displayField.setAttribute( 'autocomplete', 'off' );					// turn off browsers auto-complete on display field.
	valueField.setAttribute( 'autocomplete', 'off' );					// turn off browsers auto-complete on value field.

	pax.event.bindKeyUp( displayField, pax.widget.inputbox.keyUp);		// bind key up
	pax.event.bindKeyPress( displayField, pax.widget.inputbox.keyDown);	// bind key press
	pax.event.bind( displayField, 'blur', function( event ) {			// bind the blur event.
		var displayField = (event.srcElement)? event.srcElement : event.target;
		var cfg = displayField.inputboxConfig;
		pax.widget.inputbox.setValueAndHide( cfg.resultOffset, displayField );
	});

	//	The various search modes available. Format: searchModeString : [ icon, text ]
	//	TODO: Make this a bit more configurable...
	//	For now it assumes PAX is in "/pax"
	cfg.searchModeConfig = { 
		'default': ['<img src="/pax/widget_icons/start_icon.gif">', 'Start match'], 
		'partial': ['<img src="/pax/widget_icons/partial_icon.gif">', 'Partial match'], 
		'soundex': ['<img src="/pax/widget_icons/soundex_icon.gif">', 'Sounds like'] 
	};
	pax.widget.inputbox.showConfigIcon( displayField.id );
};


//
//	Private Method: Shows the configuration icon, depending on the selected mode.
//
pax.widget.inputbox.showConfigIcon = function( displayFieldID ) {
	var displayField = document.getElementById( displayFieldID );
	var cfg = displayField.inputboxConfig;
	if( cfg.showConfigIcon ) {
		var pos = pax.util.getPosition( displayField );
		pax.widget.inputbox.showMessageBox( displayField.id + '_icon', "<span onclick=\"pax.widget.inputbox.showConfigBox('" + displayField.id + "');return false;\">" + cfg.searchModeConfig[cfg.searchMode][0] + "</span>", 'inputboxConfigIcon', pos.x + pos.width - 19, pos.y + 3 );
	}
};


//
//	Private Method: Show the configuration box
//
pax.widget.inputbox.showConfigBox = function( displayFieldID ) {
	var displayField = document.getElementById( displayFieldID );
	var cfg = displayField.inputboxConfig;
	// Add boxes for each possible configuration
	var pos = pax.util.getPosition( displayField );
	var iconPos = pax.util.getPosition( document.getElementById( displayField.id + '_icon' ) );
	
	var myConfig = "";

	// TODO, Change the config to use a template.

	for( c in cfg.searchModeConfig ) {
		myConfig += "<span onclick=\"javascript:pax.widget.inputbox.setSearchMode('"+c+"', getElementById('" + displayFieldID + "')); pax.widget.inputbox.hideConfigBox('" + displayFieldID + "');pax.widget.inputbox.showConfigIcon('" + displayFieldID + "');return false;\">" + cfg.searchModeConfig[c][0] + "&nbsp;" + cfg.searchModeConfig[c][1] + "</span><br>";
	}

	pax.widget.inputbox.showMessageBox( displayFieldID + '_config', myConfig, 'inputboxConfigBox', pos.x + pos.width, iconPos.y );
};


//
//	Private Method: Hide the configuration box
//
pax.widget.inputbox.hideConfigBox = function( displayFieldID ) {
	pax.widget.inputbox.hideMessageBox( displayFieldID + '_config' );
};


//
//	Private Method: Sets the value, and hides the search box.
//
pax.widget.inputbox.setValueAndHide = function( index, displayField ) {
	var cfg = displayField.inputboxConfig;
	var valueField = cfg.valueField;
	if( ! cfg.allowFreetext ) {
		var disValue = pax.widget.inputbox.getDisplayResult( displayField );
		var valValue = pax.widget.inputbox.getValueResult( displayField );
		
		if( disValue != 'undefined' )displayField.value = disValue;
		if( valValue != 'undefined' )valueField.value = valValue;
	}
	pax.widget.inputbox.hideResult( displayField );
};


//
//	Private Method: Display the matching text as "normal", and the rest as selected text.
//
pax.widget.inputbox.setSelectRange = function( displayField, resultValue ) {
	matchValue = displayField.value;
	if( resultValue != false ) {
		if( resultValue.length > matchValue.length ) {
			displayField.value = resultValue;
			pax.widget.inputbox.selectRange( displayField, matchValue.length, resultValue.length );
		}
	}
};


//
//	Private Method: Select a certain part of the text in a specific text field.
//
pax.widget.inputbox.selectRange = function( displayField, start, length ) {
	if( pax.isIe ) {
		var myRange = displayField.createTextRange();
		myRange.moveStart( "character", start );
		myRange.moveEnd( "character", length );
		myRange.select();
	}
	else {
		displayField.setSelectionRange( start, length );
	}
};


//
//	Private method: Get the index result at a specific offset - useful with allowIndex
//
pax.widget.inputbox.getIndex = function( displayField ) {
	var cfg = displayField.inputboxConfig;
	count = 0;
		
	for( r in cfg.result ) {
		if( count == cfg.resultOffset )return r;
		count += 1;
	}
	
	if( ! cfg.allowFreetext ) {
		if( cfg.useIndex ) {
			return cfg.originalValue;		// If we don't get an index, set the original value.
		}
		else {
			return false;
		}
	}
};


//
//	Private method: Get the offset, from the index result
//
pax.widget.inputbox.getResultOffset = function( displayField, index ) {
	var cfg = displayField.inputboxConfig;
	count = 0;
	for( r in cfg.result ) {
		if( r == index )return count;
		count += 1;
	}
	return cfg.resultOffset;		// If we don't get an index, return the current result offset.
};


//
//	Private method: Get the selected value for display: always the value, not the key.
//
pax.widget.inputbox.getDisplayResult = function( displayField ) {
	var cfg = displayField.inputboxConfig;
	var valueField = cfg.valueField;
	myValue = '';

	myIndex = pax.widget.inputbox.getIndex( displayField );
		
	myValue = cfg.result[myIndex];
	if( typeof myValue == 'undefined' || myValue == false ) {
		return displayField.value;
	}
	
	// Note, we will get 'undefined' if the result is empty...
	if( myValue == 'undefined' )myValue = '';
	return myValue;
};


//
//	Private method: Get the selected value: could be either value or key (index)
//
pax.widget.inputbox.getValueResult = function( displayField ) {
	var cfg = displayField.inputboxConfig;
	var valueField = cfg.valueField;
	var myValue = ( cfg.useIndex )?'' + pax.widget.inputbox.getIndex( displayField ) : '' + cfg.result[pax.widget.inputbox.getIndex( displayField )];
	
	// Note, we will get 'undefined' if the result is empty...
	return ( typeof myValue == 'undefined' )? valueField.value : myValue;
};



//
//	Private method: Events that fire as key is pressed, and before the key is released
//
pax.widget.inputbox.keyDown = function( event ) {
	var displayField = (event.srcElement)? event.srcElement : event.target;
	var cfg = displayField.inputboxConfig;
	if( event.keyCode == 9 ) {			// TAB - set the value of the textbox to the offset value.
		pax.widget.inputbox.setValueAndHide( cfg.resultOffset, displayField );
		return;
	}
};


//
//	Private method: Events that fire as the key is released
//
pax.widget.inputbox.keyUp = function( event ) {
	var displayField = (event.srcElement)? event.srcElement : event.target;
	var cfg = displayField.inputboxConfig;	
	var highlight = false;
	if( event.keyCode == 40 ) {							// Arrow key down - move down list of options
		if( !pax.isIe ) { event.preventDefault(); }	// Stop keypress from propagating.
		cfg.resultOffset += 1;
		if( cfg.resultOffset > ( cfg.resultCount - 1 ) )cfg.resultOffset = cfg.resultCount -1;
		highlight = true;
	} 
	else if( event.keyCode == 38 ) {					// Arrow key up - move up list of options
		if( !pax.isIe ) { event.preventDefault(); }	// Stop keypress from propagating.
		cfg.resultOffset -= 1;
		if( cfg.resultOffset < 0 )cfg.resultOffset = 0;
		highlight = true;
	}
	else if( event.keyCode == 13 ) {					// Enter - set the value of the textbox to the offset value.
		if( !pax.isIe ) { event.preventDefault(); }	// Stop keypress from propagating.
		pax.widget.inputbox.setValueAndHide( cfg.resultOffset, displayField );
		return;
	}
	else if( event.keyCode == 27 ) {					// ESC - hide list of options
		if( !pax.isIe ) { event.preventDefault(); }	// Stop keypress from propagating.
		displayField.value = cfg.originalValue;
		pax.widget.inputbox.hideResult( displayField );
		return;
	}

	if( highlight )pax.widget.inputbox.highlightResult( displayField );
	else {
		if( displayField.value != cfg.lastSearch ) {	// Do the search via a timeout.
			window.clearTimeout( cfg.requestTimer );
			cfg.requestTimer = window.setTimeout( function(){ pax.widget.inputbox.search( displayField ) }, cfg.searchDelay );
		}
		else pax.widget.inputbox.highlightResult( displayField, cfg.result );
	}
};

//
//	Set the searchMode parameter
//
/*	Method: pax.widget.inputbox.setSearchMode
	Chooses which search mode to use, for an inputbox
	
	Parameters:		
		searchMode - which search mode to use
		displayField - which field has the config, and is used for display

	Returns:
		nothing

	Example:
		(start code)
			Try typing 'Lake cat eye', and you should get 'Lake Cathie'. "Lake cat eye" is what the locals call it ;o)
			<form name='inputBoxForm' onsubmit='return false;'>
				<span>
					<input name="pax.widget.inputbox.setSearchMode.town" id="pax.widget.inputbox.setSearchMode.town">
				</span>
			</form>
			[:.
				pax.widget.inputbox.init( pax.$('pax.widget.inputbox.setSearchMode.town'), '/pax/documentation/pax.widget.inputbox.example.php' );
				pax.widget.inputbox.setSearchMode( 'soundex', pax.$('pax.widget.inputbox.setSearchMode.town') );
				pax.widget.inputbox.showConfigIcon( 'pax.widget.inputbox.setSearchMode.town' );
				
				exampleCleanup = function() { 
					pax.widget.inputbox.hideMessageBox( 'pax.widget.inputbox.setSearchMode.town_icon' );
				};
			:]
		(end)
		This example is almost identical to the <pax.widget.inputbox.init> example, except it starts in 'sounds like' mode. 
		You should note that we must use pax.widget.inputbox.showConfigIcon to update the config icon.
*/
pax.widget.inputbox.setSearchMode = function( searchMode, displayField ) {
	var cfg = displayField.inputboxConfig;
	cfg.searchMode = ( typeof searchMode != 'undefined' ) ? searchMode : 'default';		// If the search is to match within text (ie:partially - see .php script for details)
	// Note, we can't use selectResult with special searchMode!
	if( cfg.searchMode != 'default' )cfg.selectResult = false;
};


//
//	Private method: Run the search.
//
pax.widget.inputbox.search = function( displayField ) {
	var cfg = displayField.inputboxConfig;
	
	cfg.resultCount = 0;
	cfg.resultOffset = 0;
	
	if( displayField.value.length >= cfg.minSearchLength ) {
		cfg.lastSearch = displayField.value;
		cfg.token += 1;
		pax.post( cfg.serverSearchScript, 'token=' + cfg.token + '&self=' + displayField.id + '&searchMode=' + cfg.searchMode + '&query=' + displayField.value, eval('pax.widget.inputbox.parseResult'), 'Retreiving data for ' + displayField.id );
	}
	else {
		pax.widget.inputbox.hideResult( displayField );
	}
};

//
//	Private method: Parse result, and call the show function.
//
pax.widget.inputbox.parseResult = function( xml, txt, url ) {
	var result = null;
	eval( 'var result = ' + txt );	// Turn the JSON into a local dict -> var result

	/*
		We have a pointer sent to the server called __self__, which we then remove from the result passed back.
		Note: this works! But it's kinda un-neat :o(
	*/

	
	myself = result['__self__'];

	var displayField = document.getElementById( myself );
	var cfg = displayField.inputboxConfig;

	var token = result['__token__'];

	// If this is a callback we don't want: return.
	if( token != cfg.token ) {
		return;
	}
	
	// Remove __self__ from result here
	myResult = {};
	for( r in result ) {
		if( r != '__self__' && r != '__token__' )myResult[r] = result[r];
	}

	cfg.result = myResult;											// Keep a copy, for displaying the selected option.
	pax.widget.inputbox.showResult( displayField, myResult );		// Show the result
	window.clearTimeout( cfg.requestTimer );						// Reset search request timer
};


//
//	Private method: Highlights the result that is currently selected, and un-highlights the rest.
//
pax.widget.inputbox.highlightResult = function( displayField, offset ) {
	var cfg = displayField.inputboxConfig;
	var offset = ( offset ) ? offset : cfg.resultOffset;
	resDiv = document.getElementById( cfg.resultDiv );
	if( !resDiv )return;	// If the result div hasn't been shown yet, we return.
	// Loop on the divs within the result div, and turn off.
	var myDivs = resDiv.getElementsByTagName('div');
	count = 0;
	for( d in myDivs ) {
		if( typeof myDivs[d] != 'undefined' ) {	
			if( typeof myDivs[d].id != 'undefined' ) {
				myDivs[d].className = 'inputboxResultLine';
				if( count == offset ) {
					myDivs[d].className = 'inputboxResultLineSelected';
				}
				count += 1;
			}
		}
	}
};


//
pax.widget.inputbox.showMessageBox = function( id, message, className, x, y ) {
	
	//	Only insert the box once.
	if( document.getElementById( id ) == null ) {
		//	Create a DIV next to the field
		var div = document.createElement('DIV');
		div.id = id;
		div.className = className;
		div.style.position = 'absolute';
		div.style.left = x + 'px';
		div.style.top = y + 'px';
		div.innerHTML = message;
		div.style.display = 'block';
		if( div.style.zIndex < 1 )div.style.zIndex = 3;  // Ensure that the box has a positive zIndex.
		
		document['body'].appendChild( div );
		
		// Add a transparent iFrame, so that selectboxes don't peep through
		if( pax.isIe ) {
			var pos = pax.util.getPosition( div );
			var frameId = div.id + '_iFrame';

			// Only insert iFrame, if it doesn't already exist
			if( document.getElementById( frameId ) == null ) {
				myZIndex = div.style.zIndex - 1;      // Insert iFrame layer just below Div
				// The ugly string below is an iframe with the correct parameters.
				myFrame = "<iframe src=\"javascript:false;\" id=\"" + frameId + "\" scrolling=\"no\" width=\"" + pos.width + "px\" height=\"" + pos.height + "px\" frameborder=\"0\" style=\"position:absolute;top:" + pos.y + "px;left:" + pos.x + "px;z-index:"+myZIndex+";filter:'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';\"></iframe>";
				document.body.insertAdjacentHTML('beforeEnd', myFrame);
			}
			
			// Set iFrame properties to be sure!
			myFrame = document.getElementById( frameId );
			if( myFrame ) {
				myFrame.width = div.offsetWidth;
				myFrame.height = div.offsetHeight;
				myFrame.style.top = pos.y + "px";
				myFrame.style.left = pos.x + "px";
				myFrame.style.display = div.style.display;
			}
		}
		
	}
	else div = document.getElementById( id );
	
	div.className = className;
	div.style.position = 'absolute';
	div.style.left = x + 'px';
	div.style.top = y + 'px';
	div.innerHTML = message;
	div.style.display = 'block';

	
	div.innerHTML = message;
	div.style.display = 'block';
};

//
//	Private method: This will hide the given message box, using the (optional) given function
//
pax.widget.inputbox.hideMessageBox = function( id, func ) {
	document.getElementById( id ).style.display='none';
	if( pax.isIe ) {
		document.getElementById( id + '_iFrame' ).style.display='none';
	}
};


//
//	Private method: Show the result box
//
//	We need to Allow more control over how the response box looks from the server side, use a template!
//	This really needs a cleanup :o)
pax.widget.inputbox.showResult = function( displayField, res ) {
	var cfg = displayField.inputboxConfig;
	
	// Create a DIV, and populate with results
	myDiv = document.getElementById( cfg.resultDiv );

	// 	Make sure we only create the div once.
	if( !myDiv ) {
		myDiv = document.createElement('div');
		myDiv.setAttribute('id', cfg.resultDiv);
		if( pax.isIe )myDiv.setAttribute('className', 'inputboxResult');
		else myDiv.setAttribute('class', 'inputboxResult');
		document.body.appendChild( myDiv );
		myDiv = document.getElementById( cfg.resultDiv );
	}

	myDiv.style.display = 'none';

	if( res == null )return;
	myList = '';
	count = 0;
	for( r in res ) {
		// myList += r + " = " + res[r] + "<br>\n";
		if( cfg.resultWidth > 0 ) {
			resultValue = res[r].substring(0,cfg.resultWidth);
			if( resultValue.length > cfg.resultWidth - 1 )resultValue += '...';
		}
		else {
			resultValue = res[r];
		}
		
		// Highlight the matching text in the result value here.
		matchValue = resultValue.toUpperCase();		
		boldStart = matchValue.indexOf( displayField.value.toUpperCase() );
		boldEnd   = displayField.value.length;
		matchValue = resultValue.substring( boldStart, boldStart + boldEnd );
		resultValue = resultValue.substring(0,boldStart) + '<b>' + matchValue  + '</b>' + resultValue.substring(boldStart + boldEnd, resultValue.length);

		// Could use a PTL here?...

		selectJS = " onmouseover=\"document.getElementById('" + displayField.id + "').inputboxConfig.resultOffset = pax.widget.inputbox.getResultOffset( document.getElementById('" + displayField.id + "'), " + r + ");pax.widget.inputbox.highlightResult(document.getElementById('" + displayField.id + "') );\" ";
		// selectJS = "";

		if( count == cfg.resultOffset ) {
			myList += "<div " + selectJS + " class='inputboxResultLineSelected' id='" + cfg.resultDiv + "_" + count + "'>" + resultValue + "</div>\n";
		}
		else {
			myList += "<div " + selectJS + " class='inputboxResultLine' id='" + cfg.resultDiv + "_" + count + "'>" + resultValue + "</div>\n";
		}
		count += 1;
	}
	cfg.resultCount = count;
	myDiv.innerHTML = myList;
	
	myDiv.style.display = 'block';
	
	// displayField = document.getElementById( pax.widget.inputbox.displayFieldID );
	var pos = pax.util.getPosition( displayField );
	myDiv.style.left = pos.x + 'px';
	myDiv.style.top = parseInt(pos.y + pos.height) + 'px';
	myDiv.style.width = pos.width;
	if( myDiv.style.zIndex < 1 )myDiv.style.zIndex = 3;  // Ensure that the box has a positive zIndex.

	// Add a transparent iFrame, so that selectboxes don't peep through
	if( pax.isIe )
	{
		frameId = "myIFrame_" + cfg.resultDiv;

		// Only insert iFrame, if it doesn't already exist
		if( !document.getElementById( frameId ) )
		{
			if( myDiv.style.zIndex < 1 )myDiv.style.zIndex = 1;  // Ensure that Menu has a positive zIndex.
			myZIndex = myDiv.style.zIndex - 1;      // Insert iFrame layer just below Menu
			myFrame = "<iframe src=\"javascript:false;\" id=\"" + frameId + "\" scrolling=\"no\" width=\"" + myDiv.offsetWidth + "px\" height=\"" + myDiv.offsetHeight + "px\" frameborder=\"0\" style=\"position:absolute;top:" + pos.y + "px;left:" + pos.x + "px;z-index:"+myZIndex+";filter:'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';\"></iframe>";
			document.body.insertAdjacentHTML('beforeEnd', myFrame);
		}
		
		// Set iFrame properties
		myFrame = document.getElementById( frameId );
		if( myFrame )
		{
			myFrame.width = myDiv.offsetWidth;
			myFrame.height = myDiv.offsetHeight;
			myFrame.style.top = pos.y + "px";
			myFrame.style.left = pos.x + "px";
			myFrame.style.display = myDiv.style.display;
		}
	}

	//	setSelectRange is currently not working - select range, 
	//	and update value are conflicting...
	if( cfg.selectResult ) {
		// Display the matching text as "normal", and the rest as selected text
		pax.widget.inputbox.setSelectRange( displayField, pax.widget.inputbox.getDisplayResult( displayField ) );
		displayField.focus();
	}
};


//
//	Private method: Hide the result box
//
pax.widget.inputbox.hideResult = function( displayField ) {
	var cfg = displayField.inputboxConfig;
	var myDiv = document.getElementById( cfg.resultDiv );
	if( myDiv )myDiv.style.display = 'none';

	// Hide the iFrame that is inserted if we're using IE
	if( pax.isIe ) {
		frameId = "myIFrame_" + cfg.resultDiv;
		myFrame = document.getElementById( frameId );
		if( myFrame )myFrame.style.display = 'none';
	}
};


